#pragma once

#include "SDUData.h"

#define INT_TYPE_SIZE	16
#define BOOL_TYPE_SIZE	1
#define ADDRESS_LENGTH	8
#define FUNCTION_CODE_LENGTH	6
#define PUDLENGTH_LENGTH	8
#define CRC16_LENGTH	16
#define PUDDATA_LENGTH	(2*ADDRESS_LENGTH+2*BOOL_TYPE_SIZE+FUNCTION_CODE_LENGTH+PUDLENGTH_LENGTH+SDUDATA_LENGTH+CRC16_LENGTH)
#define PUDDATA_FIELDS_COUNT	8
#define DES_ADDRESS_FIELD	0
#define SRC_ADDRESS_FIELD	1
#define COMPRESS_FIELD	2
#define ENCRYPT_FIELD	3
#define FUNCTION_CODE_FIELD	4
#define PUD_LENGTH_FIELD	5
#define SDU_DATA_FIELD	6
#define CRC16_FIELD	7

#define BINARY_FRAME_SIZE	37

class PUDData
{
public:
	PUDData(void);
public:
	~PUDData(void);
protected:
	ParseUtil _parseUtil;
public:
	int	destinationAddress;
	int	sourceAddress;
	bool isCompressed;
	bool isEncrypted;
	int functionCode;
	int PUDLength;
	SDUData sduDataBody;
	unsigned int CRC16;

	bool isDataRightByCRC16;
	char szFrame[PUDDATA_LENGTH+1];
public:
	void setFrame(char* szFrameString);

	void toBinaryDisplay(char* szPUDDataDisplay);
	void getFrameField(int fieldNo, char* szFrameFieldString);
	void setPropertiesFromFrameData();
	void toBinaryData(char* szBinaryData);
	void setBinaryData(char* szBinaryData);
};
